//grid bootstrap based
$grid-gutter-width:   $gutter;
$grid-columns:        12;

$breakpoints:         'xxs','xs','sm','md','lg';
$screen-xs:           375px;
$screen-sm:           768px;
$screen-md:           992px;
$screen-lg:           1140px;
$screen-xlg:          1900px;

$container-xs:        460px;
$container-sm:        768px;
$container-md:        990px;
$container-lg:        1000px;

$screens: "xxs" false,
          "xs" $screen-xs,
          "sm" $screen-sm,
          "md" $screen-md,
          "lg" $screen-lg;

$grid-breakpoint:     $screen-md;

@mixin container-fixed($gutter: $grid-gutter-width) {
  width: 100%;
  margin-right: auto;
  margin-left: auto;
  padding-left:  $gutter;
  padding-right: $gutter;
}

@mixin make-row($gutter: $grid-gutter-width) {
  margin-left:  ($gutter / -2);
  margin-right: ($gutter / -2);
}

@mixin make-column($columns, $gutter: $grid-gutter-width) {
  position: relative;
  float: left;
  width: percentage(($columns / $grid-columns));
  min-height: 1px;
  padding-left:  ($gutter / 2);
  padding-right: ($gutter / 2);
}

@mixin make-clear($columns, $clean: 0 ){
  &:nth-child(#{$columns}n + 1){
    clear: both;
  }
  @if $clean != 0{
    &:nth-child(#{$clean}n + 1) {
      clear: none;
    }
  }
}

@mixin make-xs-clear($columns, $clean: 0){
  @include make-clear($columns, $clean);
}

@mixin make-xxs-column($columns, $gutter: $grid-gutter-width) {
  @include make-column ($columns, $gutter);
}

@mixin make-xxs-column-offset($columns) {
  margin-left: percentage(($columns / $grid-columns));
}

@mixin make-xxs-column-push($columns) {
  left: percentage(($columns / $grid-columns));
}

@mixin make-xxs-column-pull($columns) {
  right: percentage(($columns / $grid-columns));
}

@mixin make-xs-column($columns, $gutter: $grid-gutter-width) {
  position: relative;
  min-height: 1px;
  padding-left:  ($gutter / 2);
  padding-right: ($gutter / 2);

  @media (min-width: $screen-xs) {
    float: left;
    width: percentage(($columns / $grid-columns));

  }
}

@mixin make-xs-clear($columns, $clean: 0){
  @media (min-width: $screen-xs) {
    @include make-clear($columns, $clean);
  }
}

@mixin make-xs-column-offset($columns) {
  @media (min-width: $screen-xs) {
    margin-left: percentage(($columns / $grid-columns));
  }
}

@mixin make-xs-column-push($columns) {
  @media (min-width: $screen-xs) {
    left: percentage(($columns / $grid-columns));
  }
}

@mixin make-xs-column-pull($columns) {
  @media (min-width: $screen-xs) {
    right: percentage(($columns / $grid-columns));
  }
}

@mixin make-sm-column($columns, $gutter: $grid-gutter-width) {
  position: relative;
  min-height: 1px;
  padding-left:  ($gutter / 2);
  padding-right: ($gutter / 2);

  @media (min-width: $screen-sm) {
    float: left;
    width: percentage(($columns / $grid-columns));

  }
}

@mixin make-sm-clear($columns, $clean: 0){
  @media (min-width: $screen-sm) {
    @include make-clear($columns, $clean);
  }
}

@mixin make-sm-column-offset($columns) {
  @media (min-width: $screen-sm) {
    margin-left: percentage(($columns / $grid-columns));
  }
}

@mixin make-sm-column-push($columns) {
  @media (min-width: $screen-sm) {
    left: percentage(($columns / $grid-columns));
  }
}

@mixin make-sm-column-pull($columns) {
  @media (min-width: $screen-sm) {
    right: percentage(($columns / $grid-columns));
  }
}

@mixin make-md-column($columns, $gutter: $grid-gutter-width) {
  position: relative;
  min-height: 1px;
  padding-left:  ($gutter / 2);
  padding-right: ($gutter / 2);

  @media (min-width: $screen-md) {
    float: left;
    width: percentage(($columns / $grid-columns));

  }
}

@mixin make-md-clear($columns, $clean: 0){
  @media (min-width: $screen-md) {
    @include make-clear($columns, $clean);
  }
}

@mixin make-md-column-offset($columns) {
  @media (min-width: $screen-md) {
    margin-left: percentage(($columns / $grid-columns));
  }
}

@mixin make-md-column-push($columns) {
  @media (min-width: $screen-md) {
    left: percentage(($columns / $grid-columns));
  }
}

@mixin make-md-column-pull($columns) {
  @media (min-width: $screen-md) {
    right: percentage(($columns / $grid-columns));
  }
}

@mixin make-lg-column($columns, $gutter: $grid-gutter-width) {
  position: relative;
  min-height: 1px;
  padding-left:  ($gutter / 2);
  padding-right: ($gutter / 2);

  @media (min-width: $screen-lg) {
    float: left;
    width: percentage(($columns / $grid-columns));

  }
}

@mixin make-lg-clear($columns, $clean: 0){
  @media (min-width: $screen-lg) {
    @include make-clear($columns, $clean);
  }
}

@mixin make-lg-column-offset($columns) {
  @media (min-width: $screen-lg) {
    margin-left: percentage(($columns / $grid-columns));
  }
}

@mixin make-lg-column-push($columns) {
  @media (min-width: $screen-lg) {
    left: percentage(($columns / $grid-columns));
  }
}

@mixin make-lg-column-pull($columns) {
  @media (min-width: $screen-lg) {
    right: percentage(($columns / $grid-columns));
  }
}

@mixin make-grid-columns {
  %make-grid-column{
    position: relative;
    // Prevent columns from collapsing when empty
    min-height: 1px;
    // Inner gutter via padding
    padding-left:  ($grid-gutter-width / 2);
    padding-right: ($grid-gutter-width / 2);
  }

  @each $bp in $breakpoints {
    @for $i from 1 through $grid-columns {
      .col-#{$bp}-#{$i}{
        @extend %make-grid-column;
      }
    }
  }
}

// [converter] This is defined recursively in LESS, but Sass supports real loops
@mixin float-grid-columns($class, $i: 1, $list: ".col-#{$class}-#{$i}") {
  @for $i from (1 + 1) through $grid-columns {
    $list: "#{$list}, .col-#{$class}-#{$i}";
  }
  #{$list} {
    float: left;

  }
}

@mixin calc-grid-column($index, $class, $type) {
  @if ($type == width) and ($index > 0) {
    .col-#{$class}-#{$index} {
      width: percentage(($index / $grid-columns));
    }
  }
  @if ($type == push) and ($index > 0) {
    .col-#{$class}-push-#{$index} {
      left: percentage(($index / $grid-columns));
    }
  }
  @if ($type == push) and ($index == 0) {
    .col-#{$class}-push-0 {
      left: auto;
    }
  }
  @if ($type == pull) and ($index > 0) {
    .col-#{$class}-pull-#{$index} {
      right: percentage(($index / $grid-columns));
    }
  }
  @if ($type == pull) and ($index == 0) {
    .col-#{$class}-pull-0 {
      right: auto;
    }
  }
  @if ($type == offset) {
    .col-#{$class}-offset-#{$index} {
      margin-left: percentage(($index / $grid-columns));
    }
  }
}

@mixin loop-grid-columns($columns, $class, $type) {
  @for $i from 0 through $columns {
    @include calc-grid-column($i, $class, $type);
  }
}

@mixin make-grid($class) {
  @include float-grid-columns($class);
  @include loop-grid-columns($grid-columns, $class, width);
  @include loop-grid-columns($grid-columns, $class, pull);
  @include loop-grid-columns($grid-columns, $class, push);
  @include loop-grid-columns($grid-columns, $class, offset);
}

.container {
  @include container-fixed;
  max-width: 100%;

  @media (min-width: $screen-xs) {
    max-width: $container-sm;
  }
  @media (min-width: $screen-sm) {
    max-width: $container-md;
  }
  @media (min-width: $screen-md) {
    max-width: $container-lg;
  }
  @media (min-width: $screen-lg) {
    max-width: $container-lg;
  }
}

.container-xs {
  @include container-fixed;
  max-width: $container-xs;
}
.container-sm {
  @include container-fixed;
  max-width: $container-sm;
}
.container-md {
  @include container-fixed;
  max-width: $container-md;
}
.container-lg {
  @include container-fixed;
  max-width: $container-lg;
}

.container-fluid {
  @include container-fixed;
}

// Row
.row {
  @include make-row;
}

// Columns
@include make-grid-columns;

// Extra Extra small grid
@include make-grid(xxs);

// Extra small grid
@media (min-width: $screen-xs) {
  @include make-grid(xs);
}

// Small grid
@media (min-width: $screen-sm) {
  @include make-grid(sm);
}

// Medium grid
@media (min-width: $screen-md) {
  @include make-grid(md);
}

// Large grid
@media (min-width: $screen-lg) {
  @include make-grid(lg);
}

.columns {
  display: table;
  table-layout: fixed;
  width: 100%;

  & > * {
    display: table-cell;
    vertical-align: top;
    padding-right: $gutter/2;
    padding-left: $gutter/2;
    &:first-child {
      padding-left: 0
    }
    &:last-child {
      padding-right: 0;
    }
  }
}

.clear{
  clear: both;
}

@media (max-width: $screen-xs - 1){
  .is-hidden-xxs{
    display: none !important;
  }
  [class*=is-visible]:not(.is-visible-xxs){
    display: none !important;
  }
}

@media (min-width: $screen-xs) and (max-width: $screen-sm - 1){
  .is-hidden-xs{
    display: none !important;
  }
  [class*=is-visible]:not(.is-visible-xs){
    display: none !important;
  }
}

@media (min-width: $screen-sm) and (max-width: $screen-md - 1){
  .is-hidden-sm{
    display: none !important;
  }
  [class*=is-visible]:not(.is-visible-sm){
    display: none !important;
  }
}

@media (min-width: $screen-md) and (max-width: $screen-lg - 1){
  .is-hidden-md{
    display: none !important;
  }
  [class*=is-visible]:not(.is-visible-md){
    display: none !important;
  }
}

@media (min-width: $screen-lg) {
  .is-hidden-lg{
    display: none !important;
  }
  [class*=is-visible]:not(.is-visible-lg){
    display: none !important;
  }
}
